<template>
<div class="container">
  <headers :title="title" :refresh="isRefresh" :path="path"></headers>
  <div class="content">
    <div class="list-block mar-top-0 mar-bottom-10">
      <ul>
        <li class="align-top">
          <div class="item-content">
            <div class="item-media"><i class="icon icon-f7"></i></div>
            <div class="item-inner">
              <div class="item-input">
                <textarea placeholder="请输入您要提出的问题..." v-model="message"></textarea>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <img-uploader @imgloaded="getImgSrc"></img-uploader>
    <div class="content-block">
      <div class="col-50">
        <a class="button button-big button-fill button-danger" @click="sendMesg">
          提交问题
        </a>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import $ from 'zepto'
import Headers from '../components/Headers'
import ImgUploader from '../components/ImgUploader'
import store from '../assets/js/store.min.js'

export default {
  ready () {
    $.init()
  },
  data () {
    return {
      title: '提问详情',
      path: '/message',
      message: '',
      imgsrc: [],
      submitTag: true,
      isRefresh: false
    }
  },
  methods: {
    getImgSrc (data) {
      this.$set('imgsrc', data)
    },
    sendMesg () {
      if (!this.submitTag) {
        return false
      }
      if (!this.message) {
        $.alert('留言内容不能为空')
        return false
      }
      this.submitTag = false
      $.showIndicator()
      this.$http.jsonp('http://www.mayishengcai.com/VoteManager/rest/saveMessage', {
        params: {
          content: this.message,
          customerId: store('customerId') || 0
        }
      }).then((data) => {
        $.hideIndicator()
        if (data.data.success) {
          $.alert(data.data.message, () => {
            this.$router.replace('/message')
          })
        }
        else {
          $.alert(data.data.message)
        }
      }, () => {
        $.hideIndicator()
        $.alert('网络异常')
        this.submitTag = true
      })
      return true
    }
  },
  components: {
    Headers,
    ImgUploader
  }
}
</script>
<style scoped>
.list-block textarea{height:8rem;font-size:14px!important;}
textarea::-webkit-input-placeholder{ 
  color:#c5c5c5!important; 
}
</style>